<template>
  <div>
    <el-table v-loading="loading" :data="skuList" border style="width: 100%">
      <el-table-column
        type="index"
        label="序号"
        width="80"
        align="center"
      ></el-table-column>
      <el-table-column label="SKU名称" prop="skuName"></el-table-column>
      <el-table-column label="SKU描述" prop="skuDesc"></el-table-column>
      <el-table-column label="默认照片" prop="imgDesc">
        <template v-slot="{ row }">
          <img
            :src="row.skuDefaultImg"
            alt="row"
            style="width:150px;height:150px"
          />
        </template>
      </el-table-column>

      <el-table-column label="重量(KG)" prop="weight"></el-table-column>
      <el-table-column label="价格(元)" prop="price"></el-table-column>
      <el-table-column label="操作" width="300px">
        <template v-slot="{ row, $index }">
          <el-button
            :type="`${row.isSale === 0 ? 'primary' : 'info'}`"
            :class="`el-icon-${row.isSale === 0 ? 'top' : 'bottom'}`"
            size="mini"
          >
            {{ `${row.isSale === 0 ? '上架' : '下架'}` }}
          </el-button>
          <el-button type="warning" size="mini">修改</el-button>
          <el-button type="danger" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="prev, pager, next, jumper,total,sizes"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
  </div>
</template>

<script>
import { reqSkuList } from '@/api/production/sku'
export default {
  name: 'Sku',
  data() {
    return {
      loading: false,
      skuList: [],
      currentPage: 1,
      pageSize: 10,
      total: 0
    }
  },
  mounted() {
    this.getSkuList()
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val
      this.getSkuList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getSkuList()
    },
    // 获取当前skuList
    async getSkuList() {
      let res = await reqSkuList(this.currentPage, this.pageSize)
      this.skuList = res.records
      this.total = res.total
    }
  }
}
</script>

<style></style>
